﻿using dz.db.util.core;
using dz.loger.core;
using dz.u9.jky.schema.Common;
using dz.util.core;

namespace Dz.WorkerService
{
    internal class U9Utils
    {
        private const string URL = "http://localhost:8099/api/";

        private SqlUtils sqlUtils;
        public U9Utils()
        {
            sqlUtils = new SqlUtils(Config.Instance.GetConnectionString("u9"));
        }
        public static async Task<U9CResult> Post(string controller,string method, string bizcontent)
        {
            HttpUtil util = new HttpUtil();

            LogUtil.Instance.Debug($"{URL}{controller}/{method}");
            LogUtil.Instance.Debug(bizcontent);
            WebResult result = await util.Post($"{URL}{controller}/{method}", bizcontent);

            U9CResult rtn = JsonUtil.Deserialize<U9CResult>(result.Data);

            return rtn;
        }
        public async Task<bool> CheckInv(string invCode, string org)
        {
            string sql = @$"select count(1) from CBO_ItemMaster a,Base_Organization b where a.Org = b.ID and a.Code='{invCode}' and b.Code='{org}'";

            int r = await sqlUtils.ExecuteScalar<int>(sql);

            return r > 0;
        }
    }
}
